﻿/*
 * Copyright (c) Seagull Consulting, Inc. All rights reserved. See License.txt in the project root for license information.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace SeagullConsulting.MvcAjaxControls.Web.Mvc.Helpers
{
    #region ColumnBuilder
    /// <summary>
    /// Create instances of AjaxGridColumns.
    /// </summary>
    /// <typeparam name="T">Type of model to render in the table.</typeparam>
    public class ColumnBuilder<T> where T : class
    {
        public AjaxGridBuilder<T> AjaxGridBuilder { get; set; }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tableBuilder">Instance of a AjaxGridBuilder.</param>
        public ColumnBuilder(AjaxGridBuilder<T> ajaxGridBuilder)
        {
            AjaxGridBuilder = ajaxGridBuilder;
        }

        /// <summary>
        /// Add lambda expressions to the AjaxGridBuilder.
        /// </summary>
        /// <typeparam name="TProp">Class property that is rendered in the column.</typeparam>
        /// <param name="expression">Lambda expression identifying a property to be rendered.</param>
        /// <returns>An instance of TableColumn.</returns>
        public IGridColumn<T> Expression<TProp>(string text, Expression<Func<T, TProp>> expression, ColumnFormats format = ColumnFormats.String, bool filterEnabled = false)
        {
            return AjaxGridBuilder.AddColumn(text, expression, format, filterEnabled);
        }
        public IGridColumn<T> Expression<TProp>(Expression<Func<T, TProp>> expression, ColumnFormats format = ColumnFormats.String, bool filterEnabled = false)
        {
            return AjaxGridBuilder.AddColumn(expression, format, filterEnabled);
        }
    }
    #endregion

    #region ActionColumnBuilder
    /// <summary>
    /// Create instances of AjaxGridActionColumns.
    /// </summary>
    /// <typeparam name="T">Type of model to render in the table.</typeparam>
    public class ActionColumnBuilder<T> where T : class
    {
        public AjaxGridBuilder<T> AjaxGridBuilder { get; set; }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tableBuilder">Instance of a AjaxGridBuilder.</param>
        public ActionColumnBuilder(AjaxGridBuilder<T> ajaxGridBuilder)
        {
            AjaxGridBuilder = ajaxGridBuilder;
        }

        /// <summary>
        /// Add lambda expressions to the AjaxGridBuilder.
        /// </summary>
        /// <typeparam name="TProp">Class property that is rendered in the column.</typeparam>
        /// <param name="expression">Lambda expression identifying a property to be rendered.</param>
        /// <returns>An instance of TableColumn.</returns>
        public IGridActionColumn<T> ActionLink<TProp>(string text, string action, Expression<Func<T, TProp>> expression)
        {
            return AjaxGridBuilder.AddActionColumn(text, action, expression);
        }
        public IGridActionColumn<T> ActionLink<TProp>(string text, string action, string controller, Expression<Func<T, TProp>> expression)
        {
            return AjaxGridBuilder.AddActionColumn(text, action, controller, expression);
        }
        public IGridActionColumn<T> ImageActionLink<TProp>(string text, string action, Expression<Func<T, TProp>> expression, string imageUrl)
        {
            return AjaxGridBuilder.AddActionColumn(text, action, expression, imageUrl);
        }
        public IGridActionColumn<T> ImageActionLink<TProp>(string text, string action, string controller, Expression<Func<T, TProp>> expression, string imageUrl)
        {
            return AjaxGridBuilder.AddActionColumn(text, action, controller, expression, imageUrl);
        }
    }
    #endregion
}
